const path = require('path');

const Koa = require('koa');
const koaStatic = require('koa-static');
const bodyParser = require('koa-bodyparser');

const server = new Koa();
const router = require('./routes');

// 中间件
// const { shbEnvMiddleware } = require('./middleware/shb-env-middleware');
// const { shbLoginMiddleware } = require('./middleware/shb-login-middleware');
const cors = require('koa2-origin-cors');
// model
// const { isNotLocalEnv } = require('./model/proxyConfigModel');
// util
// const { getCookie, getTokenInfo } = require('./util/HttpUtil');

server.init = async function() {
  server.use(cors({ allowAll: true }));
  
  // 参数解析
  server.use(bodyParser());
  
  // 静态资源
  server.use(
    koaStatic(path.resolve(__dirname, '../public'), { index: '_index.html' })
  );
  
  // 路由 -> 可通过 router.stack 查看堆栈信息
  server.use(router.routes());
  server.use(router.allowedMethods());
};

// server.init()
// // 启动server
// server.listen(9001)

module.exports = server;
